package com.dev.springBootDemo.reflection;

/**
 * @author zhumq
 * @date 2024/7/1 19:24
 */
// 测试反射
public class testReflection {
    public static void main(String[] args) throws ClassNotFoundException {
        // 通过反射获取CLASS类
        Class<?> c1 = Class.forName("com.dev.springBootDemo.reflection.User");
        Class<?> c2 = Class.forName("com.dev.springBootDemo.reflection.User");
        Class<?> c3 = Class.forName("com.dev.springBootDemo.reflection.User");
        Class<?> c4 = Class.forName("com.dev.springBootDemo.reflection.User");

        // hashCode全部都一样
        // 一个类只有一个Class对象
        // 一个类被加载后，类的整个结构都会被封装在一个Class对象中
        System.out.println(c1.hashCode());
        System.out.println(c2.hashCode());
        System.out.println(c3.hashCode());
        System.out.println(c4.hashCode());
    }
}

// 实体类: pojo/entity
class User {
    private String name;
    private int age;

    public User() {
    }

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}